package org.yray.sip.handler.flow;


import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.yray.sip.base.MsgEle;
import org.yray.sip.base.SipMsg;
import org.yray.sip.constant.SipCodeEnum;
import org.yray.sip.handler.MessageHandler;
import org.yray.sip.rtp.sender.ISipSessionCache;
import org.yray.sip.server.SipServerContext;
import org.yray.sip.server.SipSession;
import org.yray.sip.utils.IcspBeanHolder;

import java.util.Optional;


@Slf4j
public class Trying100Handler extends MessageHandler {


    @Override
    public String[] handler(SipMsg sipMsg, SipServerContext ssc) {
        if(CollectionUtils.isEmpty(sipMsg.getSdpList())) {
            log.info("recv Trying 100,nothing to send");
        }
        String callId= Optional.ofNullable(sipMsg.getMsgLine(MsgEle.CALL_ID)).map(String::trim).orElse(null);
        SipSession sipSession= IcspBeanHolder.getBean(ISipSessionCache.class).get(callId);
        if(sipSession!=null)
        {
            sipSession.setSipMap(sipMsg.getSipMap());
        }
        getEventFactory().sipEvent(callId, SipCodeEnum.SIP_100);
        return BLANK_STRINGS;
    }
}
